import React from "react";

export default function WithTime(WrappedComponent: any) {
    return class extends React.Component {
        state = { time: new Date() }
        timer: any
        componentDidMount() {
            this.timer = setInterval(() => this.clock(), 1000)
        }
        componentWillUnmount() {
            clearInterval(this.timer)
        }
        clock = () => {
            this.setState({
                time: new Date()
            })
        }
        render() {
            return (
                <WrappedComponent time={this.state.time} {...this.props} />
            )
        }
    }
}